package com.oxy.svc.impl;

import com.oxy.model.dao.util.DaoRegister;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.transaction.PlatformTransactionManager;

public abstract class BaseSvc {
	private DaoRegister daoHolder = null;
	private PlatformTransactionManager transactionManager = null;

	public DaoRegister getDaoHolder() {
		return daoHolder;
	}

	public void setDaoHolder(DaoRegister daoHolder) {
		this.daoHolder = daoHolder;
	}

	public PlatformTransactionManager getTransactionManager() {
		return transactionManager;
	}

	// normally, use instance of org.springframework.jdbc.datasource.DataSourceTransactionManager
	public void setTransactionManager(PlatformTransactionManager transactionManager) {
		this.transactionManager = transactionManager;
	}
	
	public TransactionStatus startTransaction() {
		DefaultTransactionDefinition def= new DefaultTransactionDefinition(); //new 一个事务              
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); //初始化事务,参数定义事务的传播类型; 
		return transactionManager.getTransaction(def); //获得事务状态 
	}
	public void commit(TransactionStatus tx) {
		transactionManager.commit(tx);
	}
	public void rollback(TransactionStatus tx) {
		transactionManager.rollback(tx);
	}
}
